package com.cloud.jucTest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class AtomicTest {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(0);
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; ++i) {
            executorService.execute(() -> {
                atomicInteger.getAndAdd(1);
                System.out.println(atomicInteger.get());
            });
        }
        executorService.shutdown();
        System.out.println("the finally result is :" + atomicInteger.get());
    }
}
